<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php include('menu.php'); ?>
</head>
<body>
<?php
include("../connect/connect.php");

//ค้นหาสินค้า
if($_POST["code_search"] != "" OR $_POST["name_search"] != "" OR $_POST["category_search"] != "" OR $_POST["quantity_search"] != "" ) {
	
		$Query = "SELECT * FROM product,producttype WHERE product.prodtype_id = producttype.prodtype_id ";
	
	if($_POST["code_search"] != "") {
		$Query .= "AND prod_barcode LIKE '%".$_POST["code_search"]."%' ";
	}
	if($_POST["name_search"] != "") {
		$Query .= "AND prod_name LIKE '%".$_POST["name_search"]."%' ";
	}
	if($_POST["category_search"] != "") {
		$Query .= "AND prodtype_name LIKE '%".$_POST["category_search"]."%' ";
	}
		$Query .= " ORDER BY prod_qtysell ";
	
} else {
	$Query = "SELECT * FROM product,producttype WHERE product.prodtype_id = producttype.prodtype_id ORDER BY prod_qtysell ";
}
$objQuery = mysql_query($Query) or die ("Error Query [".$Query."]");
?>
<div class="box">
  <div class="left"></div>
  <div class="right"></div>
    <div class="heading"><h1>จัดการคลังสินค้า</h1></div>
  <div class="content">
  <table class="list">
        <thead>
          <tr>
            <td width="16%" class="center">รหัสสินค้า</td>
            <td width="33%" class="center">ชื่อสินค้า</td>
            <td width="17%" class="center">หมวดสินค้า</td>
            <td width="14%" class="center">จำนวนสินค้าคงคลัง</td>
            <td width="20%" class="center">จัดการสินค้า</td>
          </tr>
        </thead>
        <tbody>
		<form action="<?php echo $_SERVER["PHP_SELF"];?>" name="formsearch" method="post" id="formsearch">
          <tr class="filter">
            <td align="center"><input name="code_search" type="text" id="code_search" style="text-align: center;" onkeydown="if(event.keyCode==13){formsearch.submit();}" /></td>
            <td align="center"><input name="name_search" type="text" id="name_search" style="text-align: center;" onkeydown="if(event.keyCode==13){formsearch.submit();}" /></td>
            <td align="center"><input name="category_search" type="text" id="category_search" style="text-align: center;" onkeydown="if(event.keyCode==13){formsearch.submit();}" /></td>
            <td align="center"></td>
            <td align="center"><a onclick="formsearch.submit();" class="button"><span>ค้นหา</span></a></td>
          </tr>
		  </form>
<?php
	while($row = mysql_fetch_array($objQuery))
		{
?>  
          <tr>
            <td style="text-align: center;"><?php echo $row["prod_barcode"];?></td>
            <td class="left" style="padding-left:20px"><?php echo $row["prod_name"];?></td>
            <td class="left" style="padding-left:20px"><?php echo $row["prodtype_name"];?></td>
            <td class="right" style="padding-right:50px"><?php echo $row["prod_quantity"];?></td>
            <td class="center">[ <a href="inventory_receive.php?id=<?php echo $row["prod_id"];?>">รับสินค้า</a> ] [ <a href="inventory_withdraw.php?id=<?php echo $row["prod_id"];?>">เบิกสินค้า</a> ] </td>
          </tr>
<?php
		}
?>
        </tbody>
      </table>
  </div>
</div>

</body>
</html>
